<template>
  <div class="app-container">
    <el-row>
      <el-col :span="24">
        <div class="h_top">
          <div class="bread_title">
            <span>更新故障报修工单</span>
          </div>
          <div class="save_button">
            <div v-if="out" class="buttonBox">
              <el-button type="success" icon="el-icon-check" size="mini" @click="OutHandle">委外</el-button>
            </div>
            <div v-if="carryOut" class="buttonBox">
              <el-button type="success" icon="el-icon-check" size="mini" @click="carryOutHandle">开始执行</el-button>
            </div>
            <div v-if="finish" class="buttonBox">
              <el-button type="success" icon="el-icon-check" size="mini" @click="finishHandle">执行完成</el-button>
            </div>
            <div v-if="wxBz" class="buttonBox">
              <el-button type="success" icon="el-icon-check" size="mini" @click="wxBzHandle">维修班长确认</el-button>
            </div>
            <div v-if="engineer" class="buttonBox">
              <el-button type="success" icon="el-icon-check" size="mini" @click="engineerHandle">工程师确认</el-button>
            </div>
            <div v-if="xsBz" class="buttonBox">
              <el-button type="success" icon="el-icon-check" size="mini" @click="xsBzHandle">线上班长确认</el-button>
            </div>
            <div v-if="sumUp" class="buttonBox">
              <el-button type="success" icon="el-icon-check" size="mini" @click="sumUpHandle">总结完成</el-button>
            </div>
            <div class="buttonBox">
              <el-button type="primary" icon="el-icon-back" size="mini" @click="goBack">返回</el-button>
            </div>
            <div class="buttonBox">
              <el-button type="primary" icon="el-icon-document-remove" size="mini" @click="confirmDel">删除</el-button>
            </div>
          </div>
        </div>
      </el-col>
    </el-row>
    <div>
      <el-row>
        <el-col :span="24">
          <el-form ref="form" :model="data" :inline="true" :rules="formRules">
            <el-input v-model="data.id" type="hidden" />
            <el-row :gutter="10">
              <el-col :span="4">
                <el-form-item prop="coding">
                  <div>编号</div>
                  <el-input v-model="data.coding" size="mini" disabled />
                </el-form-item>
              </el-col>
              <el-col :span="4">
                <el-form-item prop="name">
                  <div>名称</div>
                  <el-input v-model="data.name" size="mini" disabled />
                </el-form-item>
              </el-col>
              <el-col :span="4">
                <el-form-item prop="apply_id">
                  <div>报修申请</div>
                  <v-select v-model="data.apply_id" action="applyList" disabled />
                </el-form-item>
              </el-col>
              <el-col :span="4">
                <el-form-item prop="admin_id">
                  <div>负责人</div>
                  <v-select v-model="data.admin_id" disabled />
                </el-form-item>
              </el-col>
              <el-col :span="4">
                <el-form-item>
                  <div>电话</div>
                  <el-input v-model="data.admin.phone" :disabled="true" size="mini" />
                </el-form-item>
              </el-col>
              <el-col :span="4">
                <el-form-item prop="profession">
                  <div>专业</div>
                  <el-select v-model="data.profession" placeholder="请选择" size="mini" :disabled="summary">
                    <el-option v-for="(item, index) in profession" :key="index" :label="item" :value="index" />
                  </el-select>
                </el-form-item>
              </el-col>
              <el-col :span="4">
                <el-form-item>
                  <div>资产</div>
                  <el-input v-model="data.eq.name" size="mini" disabled />
                </el-form-item>
              </el-col>
              <el-col :span="4">
                <el-form-item>
                  <div>失效发现时间</div>
                  <el-input v-model="data.lose_date" size="mini" disabled />
                </el-form-item>
              </el-col>
              <el-col :span="4">
                <el-form-item prop="type">
                  <div>类别</div>
                  <el-select v-model="data.type" size="mini" :disabled="summary">
                    <el-option v-for="(item, index) in applyType" :key="index" :label="item" :value="index" />
                  </el-select>
                </el-form-item>
              </el-col>
              <el-col :span="4">
                <el-form-item prop="mode">
                  <div>故障模式</div>
                  <el-select v-model="data.mode" placeholder="请选择" size="mini" :disabled="summary">
                    <el-option v-for="(item, index) in applyMode" :key="index" :label="item" :value="index" />
                  </el-select>
                </el-form-item>
              </el-col>
              <el-col :span="4">
                <el-form-item prop="sort">
                  <div>排序</div>
                  <el-input v-model="data.sort" size="mini" />
                </el-form-item>
              </el-col>
              <el-col :span="4">
                <el-form-item>
                  <div>车间</div>
                  <el-input v-model="data.eq.workshop_name.name" size="mini" readonly />
                </el-form-item>
              </el-col>
              <el-col :span="4">
                <el-form-item>
                  <div>生产线</div>
                  <el-input v-model="data.eq.line_name.name" size="mini" readonly />
                </el-form-item>
              </el-col>
              <el-col :span="4">
                <el-form-item>
                  <div>来源类型</div>
                  <el-input v-model="data.cm_category_name" size="mini" readonly />
                </el-form-item>
              </el-col>
              <el-col :span="4">
                <el-form-item>
                  <div>提报人</div>
                  <el-input v-model="data.cr_admin.name" size="mini" readonly />
                </el-form-item>
              </el-col>
              <el-col v-if="data.status !== 0" :span="4">
                <el-form-item prop="sort">
                  <div>开始执行时间</div>
                  <el-input v-model="data.carryout_date" size="mini" disabled />
                </el-form-item>
              </el-col>
              <el-col v-if="data.status >= 5" :span="4">
                <el-form-item prop="sort">
                  <div>修理工时</div>
                  <el-input v-model="data.cost_stop" size="mini" disabled />
                </el-form-item>
              </el-col>
            </el-row>
          </el-form>
          <el-tabs>
            <el-tab-pane label="总结项目">
              <div v-if="summary">
                <el-form ref="wx_form" :model="wxData" :inline="true" :rules="wxRules">
                  <el-input v-model="data.id" type="hidden" />
                  <el-row :gutter="10">
                    <el-col :span="4">
                      <el-form-item prop="department">
                        <div>设备使用单位</div>
                        <el-input v-model="wxData.department" size="mini" />
                      </el-form-item>
                    </el-col>
                    <el-col :span="4">
                      <el-form-item prop="safe">
                        <div>保全班组</div>
                        <el-input v-model="wxData.safe" size="mini" />
                      </el-form-item>
                    </el-col>
                    <el-col :span="4">
                      <el-form-item>
                        <div>设备名称</div>
                        <el-input v-model="data.eq.name" size="mini" disabled />
                      </el-form-item>
                    </el-col>
                    <el-col :span="4">
                      <el-form-item>
                        <div>规格型号</div>
                        <el-input v-model="data.eq.spec" size="mini" disabled />
                      </el-form-item>
                    </el-col>
                    <el-col :span="4">
                      <el-form-item>
                        <div>设备编号</div>
                        <el-input v-model="data.eq.coding" size="mini" disabled />
                      </el-form-item>
                    </el-col>
                    <el-col :span="4">
                      <el-form-item>
                        <div>制造厂家</div>
                        <v-select v-model="data.eq.manufacturer_id" action="onlyManufacturerList" disabled />
                      </el-form-item>
                    </el-col>
                    <el-col :span="4">
                      <el-form-item>
                        <div>报修时间</div>
                        <el-input v-model="data.arrange_date" size="mini" disabled />
                      </el-form-item>
                    </el-col>
                    <el-col :span="4">
                      <el-form-item prop="complete_date">
                        <div>维修完成时间</div>
                        <el-date-picker v-model="wxData.complete_date" type="datetime" placeholder="选择日期时间" align="right" value-format="yyyy-MM-dd HH:mm:ss" size="mini" />
                      </el-form-item>
                    </el-col>
                    <el-col :span="4">
                      <el-form-item>
                        <div>修理工时</div>
                        <el-input v-model="wxData.cost" size="mini" disabled />
                      </el-form-item>
                    </el-col>
                    <el-col :span="12">
                      <el-form-item prop="part">
                        <div>维修部位</div>
                        <el-input v-model="wxData.part" size="mini" />
                      </el-form-item>
                    </el-col>
                  </el-row>
                  <el-row>
                    <el-form-item prop="content">
                      <div>问题描述</div>
                      <Tinymce id="wxContent" v-model="wxData.content" />
                    </el-form-item>
                  </el-row>
                  <el-row>
                    <el-form-item prop="defend">
                      <div>维护措施</div>
                      <Tinymce id="wxDefend" v-model="wxData.defend" />
                    </el-form-item>
                  </el-row>
                  <el-row>
                    <div class="buttonBox">
                      <el-button type="success" icon="el-icon-check" size="mini" @click="summaryHandle">总结</el-button>
                    </div>
                  </el-row>
                  <el-row :gutter="10">
                    <el-col v-if="wxData.create_time" :span="4">
                      <el-form-item>
                        <div>创建时间日期</div>
                        <el-input v-model="wxData.create_time" size="mini" disabled />
                      </el-form-item>
                    </el-col>
                    <el-col v-if="wxData.update_time" :span="4">
                      <el-form-item>
                        <div>最近更新</div>
                        <el-input v-model="wxData.update_time" size="mini" disabled />
                      </el-form-item>
                    </el-col>
                    <el-col v-if="wxData.create_time" :span="4">
                      <el-form-item>
                        <div>创建人</div>
                        <el-input v-model="wxData.cr_admin.name" size="mini" disabled />
                      </el-form-item>
                    </el-col>
                    <el-col v-if="wxData.update_time" :span="4">
                      <el-form-item>
                        <div>更新者</div>
                        <el-input v-model="wxData.up_admin.name" size="mini" disabled />
                      </el-form-item>
                    </el-col>
                  </el-row>
                </el-form>
              </div>
              <div v-else>
                只有工单执行完毕才可以总结
              </div>
            </el-tab-pane>
            <el-tab-pane label="所需备件">
              <el-table :data="parts.data">
                <el-table-column label="备品备件" prop="parts.name" min-width="24%">
                  <template scope="scope">
                    <span v-if="scope.row.already === 2" style="color: green">{{ scope.row.parts.name }}-{{ scope.row.parts.spec }}</span>
                    <span v-else-if="scope.row.already === 1" style="color: blue">{{ scope.row.parts.name }}-{{ scope.row.parts.spec }}</span>
                    <span v-else>{{ scope.row.parts.name }}-{{ scope.row.parts.spec }}</span>
                  </template>
                </el-table-column>
                <el-table-column label="参考编号" prop="parts.coding" min-width="18%" />
                <el-table-column label="数量" prop="number" min-width="13%">
                  <template slot-scope="scope">
                    <span v-if="scope.row.isSet">
                      <el-input v-model="editNumber" size="mini" placeholder="请输入内容" />
                    </span>
                    <span v-else>
                      {{ scope.row.number }}
                    </span>
                  </template>
                </el-table-column>
                <el-table-column label="当前数量" prop="parts.number" min-width="13%" />
                <el-table-column label="备注" prop="remark" min-width="24%">
                  <template slot-scope="scope">
                    <span v-if="scope.row.isSet">
                      <el-input v-model="editNotice" size="mini" placeholder="请输入内容" />
                    </span>
                    <span v-else>
                      {{ scope.row.remark }}
                    </span>
                  </template>
                </el-table-column>
                <el-table-column label="操作" min-width="8%">
                  <template v-slot="scope">
                    <div v-if="canAppend">
                      <div v-if="scope.row.already !== 2">
                        <span class="el-tag el-tag--info el-tag--mini cur" @click="editOrCancelPartsHandle(scope.row,scope.$index,true)">
                          {{ scope.row.isSet?'保存':"修改" }}
                        </span>
                        <span v-if="!scope.row.isSet" class="el-tag el-tag--danger el-tag--mini cur" @click="removePartsHandle(scope.row.id)">
                          删除
                        </span>
                        <span v-else class="el-tag el-tag--mini cur" @click="editOrCancelPartsHandle(scope.row,scope.$index,false)">
                          取消
                        </span>
                      </div>
                      <div v-else>-</div>
                    </div>
                    <div v-else>
                      <span>-</span>
                    </div>
                  </template>
                </el-table-column>
                <div v-if="canAppend" slot="append">
                  <el-form ref="append_form" :model="order" :inline="true" class="hf_form append_other_admin" :rules="appendRules">
                    <el-row :gutter="10">
                      <el-col :span="6">
                        <el-form-item prop="parts_id">
                          <v-select-s v-model="order.parts_id" action="partsList" :query="{add_field:'spec'}" />
                        </el-form-item>
                      </el-col>
                      <el-col :span="4">
                        <el-form-item>
                          <el-input :disabled="true" size="mini" />
                        </el-form-item>
                      </el-col>
                      <el-col :span="3">
                        <el-form-item prop="number">
                          <el-input v-model="order.number" size="mini" />
                        </el-form-item>
                      </el-col>
                      <el-col :span="3">
                        <el-form-item>
                          <el-input :disabled="true" size="mini" />
                        </el-form-item>
                      </el-col>
                      <el-col :span="6">
                        <el-form-item prop="notice">
                          <el-input v-model="order.notice" size="mini" />
                        </el-form-item>
                      </el-col>
                      <el-col :span="2">
                        <el-form-item>
                          <el-button icon="el-icon-upload2" size="mini" @click="appendPartsHandle" />
                        </el-form-item>
                      </el-col>
                    </el-row>
                    <el-row>
                      <el-button type="primary" size="mini" @click="getParts">请求</el-button>
                    </el-row>
                  </el-form>
                </div>
              </el-table>
            </el-tab-pane>
            <el-tab-pane label="描述">
              <el-row>
                <el-col :span="24">
                  <Tinymce id="content" v-model="data.content" />
                </el-col>
              </el-row>
            </el-tab-pane>
            <el-tab-pane label="工程师总结">
              <div v-if="summary">
                <el-form ref="engineer_form" :model="engineerData" :inline="true" :rules="engineerRules">
                  <el-input v-model="engineerData.id" type="hidden" />
                  <el-row :gutter="10">
                    <el-col :span="3">
                      <el-form-item prop="department">
                        <div>设备属地部门</div>
                        <el-input v-model="engineerData.department" size="mini" />
                      </el-form-item>
                    </el-col>
                    <el-col :span="3">
                      <el-form-item>
                        <div>设备名称</div>
                        <el-input v-model="data.eq.name" size="mini" disabled />
                      </el-form-item>
                    </el-col>
                    <el-col :span="3">
                      <el-form-item>
                        <div>设备编号</div>
                        <el-input v-model="data.eq.coding" size="mini" disabled />
                      </el-form-item>
                    </el-col>
                    <el-col :span="3">
                      <el-form-item prop="gx">
                        <div>设备工序</div>
                        <el-input v-model="engineerData.gx" size="mini" />
                      </el-form-item>
                    </el-col>
                    <el-col :span="3">
                      <el-form-item>
                        <div>故障报修时间</div>
                        <el-input v-model="data.arrange_date" size="mini" disabled />
                      </el-form-item>
                    </el-col>
                    <el-col :span="3">
                      <el-form-item>
                        <div>保全到场维修时间</div>
                        <el-input v-model="data.carryout_date" size="mini" disabled />
                      </el-form-item>
                    </el-col>
                    <el-col :span="3">
                      <el-form-item>
                        <div>维修结束时间</div>
                        <el-input v-model="data.complete_date" size="mini" disabled />
                      </el-form-item>
                    </el-col>
                    <el-col :span="4">
                      <el-form-item prop="stop_hour">
                        <div>生产停线时间合计（分钟）</div>
                        <el-input v-model="engineerData.stop_hour" size="mini" />
                      </el-form-item>
                    </el-col>
                    <el-col :span="5">
                      <el-form-item prop="rank">
                        <div>故障级别</div>
                        <el-select v-model="engineerData.rank" placeholder="请选择" size="mini">
                          <el-option v-for="(item, index) in cmRank" :key="index" :label="item" :value="index" />
                        </el-select>
                      </el-form-item>
                    </el-col>
                  </el-row>
                  <el-row>
                    <el-form-item prop="content">
                      <div>设备故障现象描述</div>
                      <Tinymce id="EnContent" v-model="engineerData.content" />
                    </el-form-item>
                  </el-row>
                  <el-row>
                    <el-form-item prop="why">
                      <div>5个为什么-分析</div>
                      <Tinymce id="EnWhy" v-model="engineerData.why" />
                    </el-form-item>
                  </el-row>
                  <el-row>
                    <el-form-item prop="reason">
                      <div>故障根本原因</div>
                      <Tinymce id="EnReason" v-model="engineerData.reason" />
                    </el-form-item>
                  </el-row>
                  <el-row>
                    <el-form-item>
                      <div>故障原因类别</div>
                      <el-checkbox v-model="engineerData.type1" true-label="1" false-label="0">设备基础条件不满足</el-checkbox>
                      <el-checkbox v-model="engineerData.type2" true-label="1" false-label="0">设备基础条件不满足</el-checkbox>
                      <el-checkbox v-model="engineerData.type3" true-label="1" false-label="0">忽视劣化</el-checkbox>
                      <el-checkbox v-model="engineerData.type4" true-label="1" false-label="0">设计缺陷</el-checkbox>
                      <el-checkbox v-model="engineerData.type5" true-label="1" false-label="0">人员技能水平欠缺</el-checkbox>
                    </el-form-item>
                  </el-row>
                  <el-row>
                    <el-form-item prop="flow">
                      <div>设备故障处置经过</div>
                      <Tinymce id="EnFlow" v-model="engineerData.flow" />
                    </el-form-item>
                  </el-row>
                  <el-row>
                    <el-form-item prop="defend">
                      <div>整改对策</div>
                      <Tinymce id="EnDefend" v-model="engineerData.defend" />
                    </el-form-item>
                  </el-row>
                  <el-row :gutter="30">
                    <el-col :span="12">
                      <el-form-item prop="verify_group">
                        <div>验证小组</div>
                        <el-input v-model="engineerData.verify_group" size="mini" />
                      </el-form-item>
                    </el-col>
                    <el-col :span="12">
                      <el-form-item prop="verify_date">
                        <div>验证时间</div>
                        <el-date-picker v-model="engineerData.verify_date" type="datetime" value-format="yyyy-MM-dd HH:mm:ss" size="mini" />
                      </el-form-item>
                    </el-col>
                    <el-col :span="24">
                      <el-form-item prop="state">
                        <div>对策执行情况</div>
                        <Tinymce id="EnStatus" v-model="engineerData.state" />
                      </el-form-item>
                    </el-col>
                  </el-row>
                  <el-row>
                    <el-col :span="24">
                      <el-form-item prop="checks">
                        <div>对策有效性评价</div>
                        <el-radio v-model="engineerData.checks" label="1">有效</el-radio>
                        <el-radio v-model="engineerData.checks" label="2">无效</el-radio>
                      </el-form-item>
                    </el-col>
                    <el-col :span="24">
                      <el-form-item prop="checkContent">
                        <div>对策有效性评价</div>
                        <Tinymce id="EnCheckContent" v-model="engineerData.checkContent" />
                      </el-form-item>
                    </el-col>
                  </el-row>
                  <el-row>
                    <div class="buttonBox">
                      <el-button type="success" icon="el-icon-check" size="mini" @click="summaryEngineerHandle">总结</el-button>
                    </div>
                  </el-row>
                  <el-row :gutter="10">
                    <el-col v-if="engineerData.create_time" :span="4">
                      <el-form-item>
                        <div>创建时间日期</div>
                        <el-input v-model="engineerData.create_time" size="mini" disabled />
                      </el-form-item>
                    </el-col>
                    <el-col v-if="engineerData.update_time" :span="4">
                      <el-form-item>
                        <div>最近更新</div>
                        <el-input v-model="engineerData.update_time" size="mini" disabled />
                      </el-form-item>
                    </el-col>
                    <el-col v-if="engineerData.create_time" :span="4">
                      <el-form-item>
                        <div>创建人</div>
                        <el-input v-model="engineerData.cr_admin.name" size="mini" disabled />
                      </el-form-item>
                    </el-col>
                    <el-col v-if="engineerData.update_time" :span="4">
                      <el-form-item>
                        <div>更新者</div>
                        <el-input v-model="engineerData.up_admin.name" size="mini" disabled />
                      </el-form-item>
                    </el-col>
                  </el-row>
                </el-form>
              </div>
              <div v-else>
                只有工单执行完毕才可以总结
              </div>
            </el-tab-pane>
          </el-tabs>
        </el-col>
      </el-row>
    </div>
  </div>
</template>
<script>
import API from '@/api/maintain/cm'
import { applyType, applyMode, profession, cmRank } from '@/utils/options'
import Tinymce from '@/components/Tinymce/index'
import VSelect from '@/components/select'
import VSelectS from '@/components/select-search'
export default {
  inject: ['backUrl', 'delOne', 'update', 'goUrl'],
  components: {
    Tinymce,
    VSelect,
    VSelectS
  },
  data() {
    return {
      data: {
        admin: {
          phone: ''
        },
        cr_admin: {
          name: ''
        },
        eq: {
          workshop_name: {
            name: ''
          },
          line_name: {
            name: ''
          },
          name: ''
        }
      },
      parts: {
        sel: null,
        data: []
      },
      wxData: {
        department: null
      },
      engineerData: {
        department: null
      },
      carryOut: false,
      finish: false,
      canAppend: false,
      wxBz: false,
      engineer: false,
      xsBz: false,
      summary: false,
      summaryEngineer: true,
      sumUp: false,
      out: false,
      order: {},
      applyType,
      applyMode,
      profession,
      cmRank,
      editNotice: '',
      editNumber: '',
      editId: '',
      formRules: {
        profession: [
          {
            required: true,
            message: '请选择专业',
            trigger: 'change'
          }
        ],
        type: [
          {
            required: true,
            message: '请选择类别',
            trigger: 'change'
          }
        ],
        mode: [
          {
            required: true,
            message: '请选择故障模式',
            trigger: 'change'
          }
        ],
        sort: [
          {
            required: true,
            message: '请输入排序',
            trigger: 'blur'
          }
        ]
      },
      appendRules: {
        parts_id: [
          {
            required: true,
            message: '请选择所需备件',
            trigger: 'change'
          }
        ],
        number: [
          {
            required: true,
            message: '请填写数量',
            trigger: 'blur'
          }
        ]
      },
      wxRules: {
        department: [
          {
            required: true,
            message: '请填写设备使用单位',
            trigger: 'blur'
          }
        ],
        safe: [
          {
            required: true,
            message: '请填写保全班组',
            trigger: 'blur'
          }
        ],
        complete_date: [
          {
            required: true,
            message: '请填写维修完成时间',
            trigger: 'blur'
          }
        ],
        part: [
          {
            required: true,
            message: '请填写维修部位',
            trigger: 'blur'
          }
        ],
        content: [
          {
            required: true,
            message: '请填写问题描述',
            trigger: 'change'
          }
        ],
        defend: [
          {
            required: true,
            message: '请填写维护措施',
            trigger: 'change'
          }
        ]
      },
      engineerRules: {
        department: [
          {
            required: true,
            message: '请填写设备属地部门',
            trigger: 'blur'
          }
        ],
        gx: [
          {
            required: true,
            message: '请填写设备工序',
            trigger: 'blur'
          }
        ],
        stop_hour: [
          {
            required: true,
            message: '请填写生产停线时间合计',
            trigger: 'blur'
          }
        ],
        rank: [
          {
            required: true,
            message: '请选择故障级别',
            trigger: 'change'
          }
        ]
      }
    }
  },
  created() {
    const id = this.$route.params.id
    API.getOne(id).then(response => {
      if (response.data.error_code) {
        this.$alert('您请求的报修单不存在', '错误', {
          confirmButtonText: '确定',
          callback: () => {
            this.backUrl()
          }
        })
      }
      if (response.data.status === 0) {
        this.carryOut = true
      }
      if (response.data.status === 1) {
        this.canAppend = true
        this.finish = true
        this.out = true
      }
      if (response.data.status === 2) {
        this.wxBz = true
      }
      if (response.data.status === 3) {
        this.engineer = true
      }
      if (response.data.status === 4) {
        this.xsBz = true
      }
      if (response.data.status === 5 || response.data.status === 6) {
        this.summary = true
      }
      if (response.data.serious === 1) {
        this.summaryEngineer = true
      }
      this.data = response.data
      this.parts.data = response.data.parts_list
      if (response.data.cm_wx) {
        this.wxData = response.data.cm_wx
        this.sumUp = true
        if (response.data.status === 6) {
          this.sumUp = false
        }
      }
      if (response.data.cm_engineer) {
        this.engineerData = response.data.cm_engineer
      }
      if (this.engineerData) {
        if (this.engineerData.type1) {
          if (this.engineerData.type1 === 0) {
            this.engineerData.type1 = false
          } else if (this.engineerData.type1 === 1) {
            this.engineerData.type1 = true
          }
        }
      }
    })
  },
  methods: {
    confirmDel() {
      const id = this.data.id
      this.delOne(API, id, true)
    },
    save() {
      const thisData = this.data
      const thisForm = this.$refs.form
      this.update(API, thisData, thisForm)
    },
    carryOutHandle() {
      const reviewData = {
        'status': 1,
        'id': this.data.id,
        'profession': this.data.profession,
        'mode': this.data.mode,
        'type': this.data.type
      }
      this.$refs.form.validate((valid) => {
        if (valid) {
          API.review(reviewData).then(response => {
            if (response.data.error_code === 1) {
              this.$message.success('执行！')
              this.backUrl()
            }
          })
        }
      })
    },
    appendPartsHandle() {
      const parts_data = {
        'parts_id': this.order.parts_id,
        'notice': this.order.notice,
        'number': this.order.number,
        'work_order_id': this.$route.params.id
      }

      this.$refs.append_form.validate((valid) => {
        if (valid) {
          API.appendParts(parts_data).then(response => {
            if (response.data.error_code === 1) {
              this.$message({
                message: '恭喜你，新增成功',
                type: 'success'
              })
              API.getOne(this.$route.params.id).then(response => {
                this.parts.data = response.data.parts_list
                this.order.parts_id = null
                this.order.notice = null
                this.order.number = null
              })
            } else {
              this.$message.error(response.data.message)
            }
          })
        }
      })
    },
    removePartsHandle(id) {
      const parts_data = {
        'id': id
      }
      this.$confirm('此操作将永久删除该数据, 是否继续?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        API.removeParts(parts_data).then((response) => {
          if (response.data.error_code === 1) {
            this.$message({
              message: '恭喜你，删除成功',
              type: 'success'
            })
            API.getOne(this.$route.params.id).then(response => {
              this.parts.data = response.data.parts_list
            })
          } else {
            this.$message.error(response.data.message)
          }
        })
      }).catch(() => {
        this.$message({
          type: 'info',
          message: '已取消删除'
        })
      })
    },
    editOrCancelPartsHandle(row, index, cg) {
      // 点击修改 判断是否已经保存所有操作
      for (const i of this.parts.data) {
        if (i.isSet && i.id !== row.id) {
          this.$message.warning('请先保存当前编辑项')
          return false
        }
      }
      // 是否是取消操作
      if (!cg) {
        if (!this.parts.sel.id) {
          this.parts.data.splice(index, 1)
        }
        return this.$set(this.parts.data[index], 'isSet', false)
      }
      // 提交数据
      const _this = this
      if (row.isSet) {
        (function() {
          const edit_parts_data = {
            'remark': _this.editNotice,
            'number': _this.editNumber,
            'id': _this.editId
          }
          API.editParts(edit_parts_data).then(response => {
            if (response.data.error_code === 1) {
              _this.$message({
                message: '恭喜你，更新成功',
                type: 'success'
              })
              API.getOne(_this.$route.params.id).then((res) => {
                _this.parts.data = res.data.parts_list
              })
            } else {
              this.$message.error(response.data.message)
            }
          })
        })()
      } else {
        this.parts.sel = JSON.parse(JSON.stringify(row))
        this.$set(this.parts.data[index], 'isSet', true)
        this.editNumber = this.parts.data[index].number
        this.editNotice = this.parts.data[index].remark
        this.editId = this.parts.data[index].id
      }
    },
    finishHandle() {
      const reviewData = {
        'status': 2,
        'content': this.data.content,
        'id': this.data.id
      }
      API.review(reviewData).then(response => {
        if (response.data.error_code === 1) {
          this.$message.success('修好了！（维修人员）')
          this.backUrl()
        } else {
          this.$message.error(response.data.message)
        }
      })
    },
    getParts() {
      const needData = {
        id: this.data.id
      }
      API.needParts(needData).then(response => {
        if (response.data.error_code === 1) {
          this.$message.success('请求备件，请速去库房领件！')
          this.backUrl()
        } else {
          this.$message.error(response.data.message)
        }
      })
    },
    wxBzHandle() {
      const reviewData = {
        'status': 3,
        'id': this.data.id
      }
      API.review(reviewData).then(response => {
        if (response.data.error_code === 1) {
          this.$message.success('确认！（维修班长）')
          this.backUrl()
        } else {
          this.$message.error(response.data.message)
        }
      })
    },
    engineerHandle() {
      const reviewData = {
        'status': 4,
        'id': this.data.id
      }
      API.review(reviewData).then(response => {
        if (response.data.error_code === 1) {
          this.$message.success('确认！（工程师）')
          this.backUrl()
        } else {
          this.$message.error(response.data.message)
        }
      })
    },
    xsBzHandle() {
      const reviewData = {
        'status': 5,
        'id': this.data.id
      }
      API.review(reviewData).then(response => {
        if (response.data.error_code === 1) {
          this.$message.success('确认！（线上班长）')
          this.backUrl()
        } else {
          this.$message.error(response.data.message)
        }
      })
    },
    sumUpHandle() {
      const reviewData = {
        'status': 6,
        'id': this.data.id
      }
      API.review(reviewData).then(response => {
        if (response.data.error_code === 1) {
          this.$message.success('总结完成')
          this.backUrl()
        } else if (response.data.error_code === 2) {
          this.$message.success('总结完成,前往委外工单填写信息')
          this.goUrl(`/maintain/out`)
        } else {
          this.$message.error(response.data.message)
        }
      })
    },
    summaryHandle() {
      const wx_data = {
        'department': this.wxData.department,
        'safe': this.wxData.safe,
        'complete_date': this.wxData.complete_date,
        'part': this.wxData.part,
        'content': this.wxData.content,
        'defend': this.wxData.defend,
        'equipment_id': this.data.equipment_id,
        'id': this.$route.params.id
      }
      this.$refs.wx_form.validate((valid) => {
        if (valid) {
          API.wxCm(wx_data).then(response => {
            if (response.data.error_code === 1) {
              this.$message({
                message: '恭喜你，总结成功',
                type: 'success'
              })
              API.getOne(this.$route.params.id).then(response => {
                this.wxData = response.data.cm_wx
                this.sumUp = true
              })
            } else {
              this.$message.error(response.data.message)
            }
          })
        }
      })
    },
    summaryEngineerHandle() {
      const engineer_data = {
        'department': this.engineerData.department,
        'gx': this.engineerData.gx,
        'stop_hour': this.engineerData.stop_hour,
        'rank': this.engineerData.rank,
        'content': this.engineerData.content,
        'why': this.engineerData.why,
        'reason': this.engineerData.reason,
        'type1': this.engineerData.type1,
        'type2': this.engineerData.type2,
        'type3': this.engineerData.type3,
        'type4': this.engineerData.type4,
        'type5': this.engineerData.type5,
        'flow': this.engineerData.flow,
        'defend': this.engineerData.defend,
        'verify_group': this.engineerData.verify_group,
        'verify_date': this.engineerData.verify_date,
        'state': this.engineerData.state,
        'checks': this.engineerData.checks,
        'checkContent': this.engineerData.checkContent,
        'id': this.$route.params.id,
        'eq_id': this.data.eq.id
      }
      this.$refs.engineer_form.validate((valid) => {
        if (valid) {
          API.engineerCm(engineer_data).then(response => {
            if (response.data.error_code === 1) {
              this.$message({
                message: '恭喜你，总结成功',
                type: 'success'
              })
              API.getOne(this.$route.params.id).then(response => {
                this.wxData = response.data.cm_engineer
              })
            } else {
              this.$message.error(response.data.message)
            }
          })
        }
      })
    },
    OutHandle() {
      API.out(this.$route.params.id).then(response => {
        console.log(response)
        if (response.data.error_code === 1) {
          this.$message({
            message: '委外完成',
            type: 'success'
          })
          this.goUrl(`/maintain/out/out_edit/${response.data.id}`)
        } else {
          this.$message.error(response.data.message)
        }
      })
    },
    goBack() {
      this.goUrl('/maintain/cm')
    }
  }
}
</script>
